package com.AAL.Utils;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	/*
	 * Dinh dang kieu timeStamp
	 */
	public static Timestamp formatTimestamp(Timestamp datetime) {
		try {
			DateFormat formatter;
			String dateFormat = datetime.toString();
			System.out.println("Truoc:"+ datetime);
			formatter = new SimpleDateFormat("dd/MM/yyyy");
			Date date = (Date) formatter.parse(dateFormat);			
			java.sql.Timestamp timeStampDate = new Timestamp(date.getTime());
			System.out.println("Sau:"+ timeStampDate);
			return timeStampDate;
		} catch (ParseException e) {
			System.out.println("Exception :" + e);
			return null;
		}
	}
	/*
	 * Ham chuyen doi kieu du lieu sang kieu TimeStamp ung voi kieu datetime trong csdl
	 */
	public static Timestamp convertStringToTimestamp(String str_date) {
		try {
			DateFormat formatter;
			formatter = new SimpleDateFormat("dd/MM/yyyy");
			Date date = (Date) formatter.parse(str_date);
			java.sql.Timestamp timeStampDate = new Timestamp(date.getTime());

			return timeStampDate;
		} catch (ParseException e) {
			System.out.println("Exception :" + e);
			return null;
		}
	}

	// ho tro lay ngay hien tai va chuyen thanh kieu TimeStamp
	public static Timestamp getToday() {
		return new Timestamp(Calendar.getInstance().getTime().getTime());
	}
}
